﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using DBBase;
using System.Threading;
using System.Xml;


using System.Web;

using System.Runtime.InteropServices;
using System.IO;
using System.Data.OleDb;
using System.Data.SqlClient;

namespace Business
{
    public partial class but_config : Form
    {
        public MainForm m_mainform;

        public static string sDataBaseIp;
        public static string sDataBaseName;
        public static string sDataBaseUserName;
        public static string sDataBasePwd;
        public static string sWebService = "";
        public static string sjyjgbh = "";
        public static string ssqm = "";
        private TextBox[] ctextbox;
        public static string[] czdm;
        public static string[] cgjd;

        public but_config()
        {
            InitializeComponent();
            ctextbox = new TextBox[41] {textBox2, textBox3, textBox4, textBox5, textBox6, textBox7, textBox8, textBox9, textBox10, textBox11, textBox12, textBox13, textBox14, textBox15, textBox16, textBox17, textBox18, textBox19, textBox20, textBox21, textBox22, textBox23, textBox24, textBox25, textBox26, textBox27, textBox28, textBox29, textBox30, textBox31, textBox32, textBox33, textBox34, textBox35, textBox36, textBox37, textBox38, textBox39, textBox40, textBox41, textBox42 };
            czdm = new string[41] { "XZ_1", "XZ_2", "XZ_3", "XZ_4", "XZ_5", "XZ_6", "XZ_7", "XZ_8", "XZ_9", "XZ_10", "XZ_11", "XZ_12", "XZ_13", "XZ_14", "XZ_15", "XZ_16", "XZ_17", "XZ_18", "XZ_19", "XZ_20", "XZ_21", "XZ_22", "XZ_23", "XZ_24", "XZ_25", "XZ_26", "XZ_27", "XZ_28", "XZ_29", "XZ_30", "XZ_31", "XZ_32", "XZ_33", "XZ_34", "XZ_35", "XZ_36", "XZ_37", "XZ_38", "XZ_39", "XZ_40", "XZ_41" };
            cgjd = new string[41] { "jczbh", "jczmc", "sflw", "rdsbh", "rdyxqs", "rdyxqz", "shejirjcnl", "shijirjcnl", "jcryzs", "wjgwrs", "lrgwrs", "ycyrs", "dpgwrs", "zjgwrs", "qtgwrs", "tgszjbmkhrs", "wtgszjbmkhrs", "fzjg", "glbm", "gxrq", "bz", "shejirjcmtsl", "shijirjcmtsl", "shbj", "syglbm", "shyj", "zt", "ztyy", "dwdz", "yzbm", "xkjyfw", "rdsffdw", "frdb", "frdbsfzh", "frdblxdh", "fzr", "fzrsfzh", "fzrlxdh", "rclxr", "rclxrsfzh", "rclxrlxdh" };
           
            
        }
       
        private void button1_Click(object sender, EventArgs e)
        {
           
        }
         
        public void lianwangchaxunjieyan()
        {
            string vehispara = "";
            string stoubao = "<?xml version=\"1.0\" encoding=\"GBK\"?>";
            vehispara = stoubao + string.Format("<root><QueryCondition><jczbh>{0}</jczbh><gxrq>{1}</gxrq></QueryCondition></root>", 
                textBox1.Text,
                 dateTimePicker1.Value.ToString("yyyy-MM-dd"));

            WebReference.Service m_sshenhe18C50 = new WebReference.Service();
            m_sshenhe18C50.Url = sWebService;
            string str = decode(m_sshenhe18C50.queryObjectOut("18", ssqm, "18C01", vehispara));
            MessageBox.Show(str);
           
            if (str.Length < 1)
            {
                MessageBox.Show("连接不到服务器");

            }
            else
            {
                XmlDocument xmlstr = new XmlDocument();
                xmlstr.LoadXml(str);
                if (xmlstr.SelectSingleNode("/root/head/code").InnerText == "1")
                {
                    //textBox2.Text = decode(xmlstr.SelectSingleNode("/root/body/vehispara/clsbdh").InnerText);
                    for (int i = 0; i < 41; i++)
                    {
                        ctextbox[i].Text = decode(xmlstr.SelectSingleNode(string.Format(@"/root/body/vehispara/{0}", cgjd[i])).InnerText);
                    }
                }
            }
        }
        public string decode(string str)//utf8转中文
        {
            Encoding utf8 = Encoding.UTF8;
            // 首先用utf-8进行解码                    
            return HttpUtility.UrlDecode(str.ToUpper(), utf8);
        }
        public string encode(string str)//中文转utf8
        {
            Encoding utf8 = Encoding.UTF8;
            return HttpUtility.UrlEncode(str, utf8);
        }
       

        private void but_add_Click(object sender, EventArgs e)
        {
           
        }

        private void but_download_Click(object sender, EventArgs e)
        {
            //判断是否核心功能
            if (m_mainform.shxgn.Contains("检验机构备案信息下载"))
            {
                m_mainform.baocunhxrj("检验机构备案信息下载", string.Format("检验机构备案信息下载"), "写入");// 核心功能日记  日记内容
            }
            lianwangchaxunjieyan();
        }

        private void but_save_Click(object sender, EventArgs e)
        {
            Query objquery = new Query();
            for (int i = 0; i < 41; i++)
            {
                objquery.UpdateTable(string.Format(@"update jyjgxxxz18c01 set {0}='{1}' where jyjgxxxz_ID=1 ", czdm[i], ctextbox[i].Text));
            }
            //保存操作日记
            m_mainform.savecaozuoriji("update jyjgxxxz18c01", "更新", "业务系统", "下载检测机构信息");
        }

        private void jyjgxxxz18C01_Load(object sender, EventArgs e)
        {

          
            Query mquery = new Query();
            string ssql;
            ssql = string.Format(@"Select * From StationInfor ");

            sWebService = mquery.GetDBString(ssql, "SI_WEB");
            sjyjgbh = mquery.GetDBString(ssql, "SI_JCZBH");
            ssqm = mquery.GetDBString(ssql, "SI_SQM");

            //判断是否民警
            if (m_mainform.sfjy.Contains("检验机构备案信息下载"))
            {
                if (!m_mainform.SFMJ.Contains("是"))
                {
                    but_download.Enabled = false;
                }
            }
            getbiaozhun();

            if (!m_mainform.squanxian.Contains("检验机构备案信息下载增加"))
            {
                but_save.Enabled = false;
            }

            if (!m_mainform.squanxian.Contains("检验机构备案信息下载编辑"))
            {
                skinButton2.Enabled = false;
            }

            if (!m_mainform.squanxian.Contains("检验机构备案信息下载删除"))
            {
                skinButton1.Enabled = false;
            }

        }

        private void skinButton1_Click(object sender, EventArgs e)
        {
            //Query mquery = new Query();
            //mquery.UpdateTable(string.Format(@"delete jyjgxxxz18c01  "));

            Query objquery = new Query();
            for (int i = 0; i < 41; i++)
            {
                objquery.UpdateTable(string.Format(@"update jyjgxxxz18c01 set {0}='{1}' where jyjgxxxz_ID=1 ", czdm[i],""));
            }
            //保存操作日记
            m_mainform.savecaozuoriji("delete jyjgxxxz18c01  where jyjgxxxz_ID=1", "删除", "业务系统", "删除检测机构信息");
            getbiaozhun();
        }

        public void getbiaozhun()
        {
            Query objquery = new Query();
            string ssqlex = "";
            ssqlex = string.Format(@"Select * From  jyjgxxxz18c01 ");
            DataTable dt = objquery.GetTable(ssqlex);
            if (dt.Rows.Count > 0)
            {
                for (int i = 0; i < 1; i++)
                {
                    for (int k = 0; k < 41; k++)
                    {
                        ctextbox[k].Text = dt.Rows[i][czdm[k]].ToString().Trim();
                    }
                        

                }
            }
        }

        private void skinButton2_Click(object sender, EventArgs e)
        {
            Query objquery = new Query();
            for (int i = 0; i < 41; i++)
            {
                objquery.UpdateTable(string.Format(@"update jyjgxxxz18c01 set {0}='{1}' where jyjgxxxz_ID=1 ", czdm[i], ctextbox[i].Text));
            }
            //保存操作日记
            m_mainform.savecaozuoriji("update jyjgxxxz18c01", "更新", "业务系统", "下载检测机构信息");
        }
    }
}
